package jmvcclab.View;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class NumPanel extends JPanel implements ActionListener{
    private JButton[] nums;
    private IOPanel text;

    public NumPanel(IOPanel t){
        text=t;
        this.setLayout(new GridLayout(4,3, 10, 10));
        nums = new JButton[13];

        for (Integer i=1; i<10; i++) {
            nums[i]=new JButton(i.toString());
        }

        nums[10] = new JButton("CE");
        nums[10].setBackground(Color.red);
        nums[10].setForeground(Color.white);
        nums[10].setBorderPainted(false);

        nums[11] = new JButton("0");
        nums[12] = new JButton(",");


        for (Integer i=1; i<13; i++) {
            nums[i].addActionListener(this);
            this.add(nums[i]);
        }
    }
    public JButton getNum(int i){
        if (i>0 && i<13) return nums[i];
        else return null;
    }
    public void actionPerformed(ActionEvent e){
        for (int i=1;i<13;i++){
           if(e.getSource()==getNum(i)) text.addText(e.getActionCommand());
        }
        if (e.getSource()==getNum(10)) text.setText("");
    }
}
